﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace TweetMemeNET
{
    public class TweetMemeResultUrlInfo : TweetMemeResultBase, ITweetMemeResult
    {
        public TweetMemeResultUrlInfo(string xml) : base(xml)
        {
            
        }

        protected override void ParseResultXml()
        {
            // Retrieve string properties
            Title = GetStoryElementValue("title").ToString();
            Url = GetStoryElementValue("url").ToString();
            Excerpt=GetStoryElementValue("excerpt").ToString();

            // Parse DateTime properties
            Created=DateTime.Parse(GetStoryElementValue("created_at"));

            // Get integer values
            string urlCountValue = GetStoryElementValue("url_count");
            string commentCountValue = GetStoryElementValue("comment_count");

            // Parse integer values
            NumberOfRetweets=int.Parse(!string.IsNullOrEmpty(urlCountValue) ? urlCountValue : "0");
            NumberOfComments=int.Parse(!string.IsNullOrEmpty(commentCountValue) ? commentCountValue : "0");

            // Determine media type
            switch(GetStoryElementValue("media_type"))
            {
                case "news":
                    MediaType=TweetMemeMediaType.News;
                    break;
                case "video":
                    MediaType=TweetMemeMediaType.Video;
                    break;
                case "image":
                    MediaType=TweetMemeMediaType.Image;
                    break;
                default:
                    MediaType=TweetMemeMediaType.Unknown;
                    break;
            }
        }

        public string Title { get; protected set; }
        public string Url { get; protected set; }
        public TweetMemeMediaType MediaType { get; protected set; }
        public DateTime Created { get; protected set; }
        public int NumberOfRetweets { get; protected set; }
        public int NumberOfComments { get; protected set; }
        public string Excerpt { get; protected set; }
    }
}